package drivers

import (
	//`MediaSortingServer/MeetGo`
	"fmt"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

// NewGBase8aDialector 创建gbase数据库驱动
func NewGBase8aDialector(host, userName, password, database string, port int) gorm.Dialector {
	// GBase 8a 的 DSN (数据源名称)
	// 格式: "user:password@tcp(host:port)/dbname?charset=utf8mb4&parseTime=True&loc=Local"
	//dsn := "your_user:your_password@tcp(your_host:your_port)/your_dbname?charset=utf8mb4&parseTime=True&loc=Local"

	dsn := BuildGBase8aDsn(host, userName, password, database, port)
	fmt.Println("gbase8a数据库连接信息dsn：", dsn)
	//MeetGo.Log.Info("db-gorm-database-gbase8a数据库连接信息dsn:%s", dsn)
	return mysql.Open(dsn)
}

func BuildGBase8aDsn(host, userName, password, database string, port int) string {
	return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", userName, password, host, port, database)
}
